package com.skynet.spms.client.gui.basedatamanager.stockServiceBusiness.stockManageTool.stockTemperatureAndHumidity;

import com.skynet.spms.client.PanelFactory;
import com.skynet.spms.client.ShowcasePanel;
import com.skynet.spms.client.entity.DataInfo;
import com.skynet.spms.client.feature.data.DataSourceTool;
import com.skynet.spms.client.feature.data.DataSourceTool.PostDataSourceInit;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;

public class StockTemperatureAndHumidityRecordPanel extends ShowcasePanel{
	
	private static final String DESCRIPTION = "库房温湿度信息维护页面";

	private StockTemperatureAndHumidityRecordListGrid stockTemperatureAndHumidityRecordListGrid;
	private StockTemperatureAndHumidityItemListGrid stockTemperatureAndHumidityItemListGrid;
	private StockTemperatureAndHumidityRecordButtonPanel stockTemperatureAndHumidityRecordButtonPanel;
	
	public static class Factory implements PanelFactory {

		private String DESCRIPTION = "库房温湿度管理模块";
		private String id;
		
		public Canvas create() {
			StockTemperatureAndHumidityRecordPanel panel = new StockTemperatureAndHumidityRecordPanel();		
			id = panel.getID();
			return panel;
		}
		
		public String getID() {
			return id;
		}
		
		public String getDescription() {
			return DESCRIPTION;
		}
	}
	
	public Canvas getViewPanel() {
		
		// 主Layout
		final VLayout mainPanelLayout = new VLayout();
		mainPanelLayout.setLayoutTopMargin(5);
		mainPanelLayout.setMembersMargin(2);
		mainPanelLayout.setWidth100();
		mainPanelLayout.setHeight100();
		// 主列表Grid
		stockTemperatureAndHumidityRecordListGrid = new StockTemperatureAndHumidityRecordListGrid();
		stockTemperatureAndHumidityRecordListGrid.setHeight("50%");
		// 获取数据源
		String modeName = "stockServiceBusiness.stockManageTool.stockTemperatureAndHumidityRecord";
		String dsName = "stockTemperatureAndHumidityRecord_dataSource";
		// 取得Grid中需要显示的数据源
		DataSourceTool dataSourceTool = new DataSourceTool();
		dataSourceTool.onCreateDataSource(modeName, dsName,
				new PostDataSourceInit() {
					public void doPostOper(DataSource dataSource,
							DataInfo dataInfo) {
						stockTemperatureAndHumidityRecordListGrid.setDataSource(dataSource);
						stockTemperatureAndHumidityRecordListGrid.fetchData();
						stockTemperatureAndHumidityRecordListGrid.drawTemperatureManageListGridField();
					}
				});
		// 明细列表Grid
		stockTemperatureAndHumidityItemListGrid = new StockTemperatureAndHumidityItemListGrid();
		stockTemperatureAndHumidityItemListGrid.setHeight("100%");
		// 获取数据源
		String detailmodeName = "stockServiceBusiness.stockManageTool.stockTemperatureAndHumidityRecord";
		String detaildsName = "stockTemperatureAndHumidityItem_dataSource";
		DataSourceTool detaildataSourceTool = new DataSourceTool();
		detaildataSourceTool.onCreateDataSource(detailmodeName, detaildsName,
				new PostDataSourceInit() {
					public void doPostOper(DataSource dataSource,
							DataInfo dataInfo) {
						stockTemperatureAndHumidityItemListGrid.setDataSource(dataSource);
						stockTemperatureAndHumidityItemListGrid.drawTemperatureManageListGridField();
					  
					}

				});
		// 共用按钮面板
		stockTemperatureAndHumidityRecordButtonPanel = new StockTemperatureAndHumidityRecordButtonPanel(
				stockTemperatureAndHumidityRecordListGrid);
		
		// 加载各面板到容器
		HLayout detailHLayout = new HLayout();
		detailHLayout.addMember(stockTemperatureAndHumidityItemListGrid);
		
		VLayout detailVLayout = new VLayout();
		detailVLayout.addMember(detailHLayout);
		
		// 主列表面板
		SectionStackSection headSection = new SectionStackSection("库房温湿度管理");
		headSection.setItems(stockTemperatureAndHumidityRecordListGrid);
		headSection.setExpanded(true);
		
		// 明细列表面板
		SectionStackSection detailSection = new SectionStackSection("库房温湿度明细");
		detailSection.setItems(detailVLayout);
		detailSection.setExpanded(true);
		
		// 主Section容器
		final SectionStack mainPanelSection = new SectionStack();
		mainPanelSection.setHeight100();
		mainPanelSection.setVisibilityMode(VisibilityMode.MULTIPLE);
		mainPanelSection.setAnimateSections(true);
		
		// 明细Section容器
		final SectionStack detailPanelSection = new SectionStack();
		detailPanelSection.setHeight100();
		detailPanelSection.setVisibilityMode(VisibilityMode.MULTIPLE);
		detailPanelSection.setAnimateSections(true);
		detailPanelSection.addSection(detailSection);
		
		// 加载各面板到容器
		mainPanelSection.addSection(headSection);
		mainPanelSection.addSection(detailSection);
		mainPanelLayout.addMember(stockTemperatureAndHumidityRecordButtonPanel);
		mainPanelLayout.addMember(mainPanelSection);

		return mainPanelLayout;
	}
	
}
